package com.hnas.eCard.dao.impl;

import java.util.Date;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import com.hnas.core.dao.BaseDaoImpl;
import com.hnas.core.util.DateUtil;
import com.hnas.core.util.StringUtil;
import com.hnas.eCard.dao.AccChannelReDao;
import com.hnas.eCard.orm.AccChannelRe;

@Component("accChannelReDao")
public class AccChannelReDaoImpl extends BaseDaoImpl<AccChannelRe> implements AccChannelReDao {

	public AccChannelReDaoImpl() {
		super(AccChannelRe.class);
	}

	@Override
	public AccChannelRe saveOrUpdate(AccChannelRe vo) {
		AccChannelRe entity = null;
		if(vo != null) {
			if(StringUtil.isNotEmpty(vo.getId())) {
				entity = this.find(vo.getId());
			}
			if(entity == null) {
				entity = new AccChannelRe();
				BeanUtils.copyProperties(vo, entity);
				entity.setCreateTime(DateUtil.dateTimeToString(new Date()));
				entity.setUpdateTime(DateUtil.dateTimeToString(new Date()));
				entity.setIsDeleted(false);
				this.persist(entity);
			}else {
				BeanUtils.copyProperties(vo, entity, new String[]{"id", "createTime"});
				entity.setUpdateTime(DateUtil.dateTimeToString(new Date()));
				this.merge(entity);
			}
		}
		return vo;
	}

}
